package com.wyp168.juc;

/**
 * @ClassName SynchroizedDemo001
 * @Description TODO
 * @Author wyp168
 * @Date 2022/7/15 09:33
 */
public class SynchronizedDemo001 {

    public static void main(String[] args) throws InterruptedException {
        Thread threadA = new Thread(new ThreadDemo());
        Thread threadB = new Thread(new ThreadDemo());
        threadA.start();
        threadB.start();

        threadB.join();
        System.out.println("All Thread exec over!");
    }

}

class ThreadDemo implements Runnable {
    public static Integer num = 0;

    @Override
    public void run() {
        synchronized (num) {
            while (num < 1000) {
                System.out.println(Thread.currentThread().getName() + "------>" + num++);
            }
        }
    }
}
